package com.ljs.controller;

import com.ljs.entity.Menu;
import com.ljs.service.MenuService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuHaddler {
    @Resource
    MenuService menuService;
    @Value("${server.port}")
    private  String port;
    @GetMapping("/index")
    public  String menu(){
        return "menu的端口是"+port;
    }

    @RequestMapping("/findall/{index}/{limit}")
    public List<Menu> sel(@PathVariable("index") int index, @PathVariable("limit") int limit){

        return menuService.selAll(index,limit);
    }
    @RequestMapping("/count")
    public  int selCount(){
        return menuService.selcount();
    }
    @RequestMapping("/name/{na}")
    public  String name(@PathVariable("na") String name){
    return  name+"有"+menuService.selbyname(name);
    }
    @RequestMapping("/upd/{id}")
    public  Menu selbyid(@PathVariable("id") int id){
        return menuService.selbyid(id);
    }
    @RequestMapping("/update")
    public  boolean update(@RequestBody Menu menu){

        return  menuService.updatemenu(menu);
    }
    @RequestMapping("/all")
    public List<Menu> all(){
        return menuService.all();
    }
    @RequestMapping("/delete/{id}")
    public  boolean delete(@PathVariable("id") int id){
        return menuService.delete( id);
    }
    @RequestMapping("/save")
    public  boolean save(@RequestBody  Menu menu){
       return menuService.insertmenu(menu);

    }
}
